﻿using DevExpress.Utils.Extensions;
using DevExpress.XtraBars;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 测试项目
{
    public partial class MenuFormDemo : Marmat.Forms.Skin.Form
    {
        public MenuFormDemo()
        {
            InitializeComponent();
        }

        private void MenuFormDemo_Load(object sender, EventArgs e)
        {

        }

        private void accordionControl1_ElementClick(object sender, DevExpress.XtraBars.Navigation.ElementClickEventArgs e)
        {

            //var buttons = new List<Label> { };
            //switch (e.Element.Name)
            //{
            //    case "常用":
            //        this.flowLayoutPanel1.Controls.Clear();
            //        buttons.Add(new Label { Text = "常用", AutoSize = false, Height = 24, TextAlign = ContentAlignment.MiddleCenter });
            //        this.flowLayoutPanel1.Controls.AddRange(buttons.ToArray());
            //        break;
            //    case "订单":
            //        this.flowLayoutPanel1.Controls.Clear();
            //        buttons.Add(new Label { Text = "订单", AutoSize = false, Height = 24, TextAlign = ContentAlignment.MiddleCenter });
            //        this.flowLayoutPanel1.Controls.AddRange(buttons.ToArray());
            //        break;
            //    case "送货单":
            //        this.flowLayoutPanel1.Controls.Clear();
            //        buttons.Add(new Label { Text = "送货单", AutoSize = false, Height = 24, TextAlign = ContentAlignment.MiddleCenter });
            //        this.flowLayoutPanel1.Controls.AddRange(buttons.ToArray());
            //        break;
            //    case "系统设置":
            //        this.flowLayoutPanel1.Controls.Clear();
            //        this.flowLayoutPanel1.Controls.Add(new Label { Text = "用户设置", AutoSize = false, Height = 24, TextAlign = ContentAlignment.MiddleCenter });
            //        break;
            //}
        }

        private void MenuFormDemo_PaintFormSkin(object Sender, PaintEventArgs e)
        {
            //e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(255, 14, 149, 255)), e.ClipRectangle);
            //e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(255, 111, 112, 114)), e.ClipRectangle);
            // e.Graphics.FillRectangle(new SolidBrush(Color.White), e.ClipRectangle);
        }

        private void label1_MouseEnter(object sender, EventArgs e)
        {
            if (sender is Label label)
            {
                label.BackColor = Color.FromArgb(255, 120, 149, 255);
            }
        }

        private void label1_MouseLeave(object sender, EventArgs e)
        {
            if (sender is Label label)
            {
                label.BackColor = Color.FromArgb(255, 111, 112, 114);
            }
        }

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            if (sender is Label label)
            {
                label.BackColor = Color.FromArgb(255, 14, 200, 255);
            }
        }

        private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            if (sender is Label label)
            {
                label.BackColor = Color.FromArgb(255, 111, 112, 114);
            }
        }

        private void label5_MouseUp(object sender, MouseEventArgs e)
        {
            if (sender is Label label)
            {
                label.BackColor = Color.FromArgb(255, 38, 85, 140);
            }
        }

        private void label5_MouseLeave(object sender, EventArgs e)
        {

            if (sender is Label label)
            {
                label.BackColor = Color.FromArgb(255, 38, 85, 140);
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        public void FillRoundRectangle(Graphics g, Rectangle rectangle, Brush brush, int r)
        {
            //确定圆角实心矩形初始X、Y位置和Width、height宽高
            rectangle = new Rectangle(rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
            //绘制圆角实心矩形
            g.FillPath(brush, this.GetRoundRectangle(rectangle, r));
        }

        /// <summary>  
        /// 根据普通矩形得到圆角矩形的路径  
        /// </summary>  
        /// <param name="rectangle">原始矩形</param>  
        /// <param name="r">半径</param>  
        /// <returns>图形路径</returns>  
        public GraphicsPath GetRoundRectangle(Rectangle rectangle, int r)
        {
            int l = 2 * r;
            // 把圆角矩形分成八段直线、弧的组合，依次加到路径中  
            GraphicsPath gp = new GraphicsPath();
            gp.AddLine(new Point(rectangle.X + r, rectangle.Y), new Point(rectangle.Right - r, rectangle.Y));
            gp.AddArc(new Rectangle(rectangle.Right - l, rectangle.Y, l, l), 270F, 90F);

            gp.AddLine(new Point(rectangle.Right, rectangle.Y + r), new Point(rectangle.Right, rectangle.Bottom - r));
            gp.AddArc(new Rectangle(rectangle.Right - l, rectangle.Bottom - l, l, l), 0F, 90F);

            gp.AddLine(new Point(rectangle.Right - r, rectangle.Bottom), new Point(rectangle.X + r, rectangle.Bottom));
            gp.AddArc(new Rectangle(rectangle.X, rectangle.Bottom - l, l, l), 90F, 90F);

            gp.AddLine(new Point(rectangle.X, rectangle.Bottom - r), new Point(rectangle.X, rectangle.Y + r));
            gp.AddArc(new Rectangle(rectangle.X, rectangle.Y, l, l), 180F, 90F);
            return gp;
        }

        private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {
            //using (Brush brush = new SolidBrush(Color.FromArgb(40, 65, 120)))
            //{
            //    var _rect = new Rectangle(flowLayoutPanel1.Location.X, flowLayoutPanel1.Location.Y, flowLayoutPanel1.Width, flowLayoutPanel1.Height);
            //    this.FillRoundRectangle(e.Graphics, _rect, brush, 10);
            //}
        }

        private void MenuFormDemo_MaximizedBoundsChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Test");
        }

        private void MenuFormDemo_MaximumSizeChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Test");

        }
    }
}
